package com.struct.graph.create_role
{
	import com.collection.ACollection;
	import com.collection.ActionCollection;
	import com.collection.DataWorkerCollection;
	import com.collection.FactoryCollection;
	import com.events.CreateRoleSelectEvent;
	
	import data.UserData;
	
	import flash.display.DisplayObjectContainer;
	import flash.events.MouseEvent;
	import flash.utils.Dictionary;
	
	import sacu.s.FactoryEvent;
	import sacu.s.worker.DataWorker;
	import sacu.s.worker.GraphWorker;
	
	public class CreateRoleGraphWorker extends GraphWorker
	{
		private var _base:CreateRoleFrame;
		
		private var current:CreateRoleShow;
		public function CreateRoleGraphWorker(id:String, base:DisplayObjectContainer)
		{
			super(id, base);
			addEventDispatcher(ActionCollection.ZIP_INIT);
			_base = base as CreateRoleFrame;
			_base.addEventListener(ACollection.SELECTED, selectedRoleHandler);
			_base.btnSubmit.addEventListener(MouseEvent.CLICK, clickHandler);
		}
		private function selectedRoleHandler(e:CreateRoleSelectEvent):void{
			if(current){
				current.selected = false;
			}
			current = e.rs;
		}
		private function clickHandler(e:MouseEvent):void{
			UserData.name = _base.txtName.text;
			UserData.role = current.roleSource;
			factory.disposeFactory();
			
			FactoryCollection.serverList.startFactory();
		}
		public function loadInfo():void{
			if(DataWorkerCollection.zip.state == 2){
				DataWorkerCollection.zip.update();
			} else {
				DataWorkerCollection.zip.update2origin();
			}
		}
		override public function handleAction(action:FactoryEvent):void{
			switch(action.type){
				case ActionCollection.ZIP_INIT:{
					_base.setValue(DataWorkerCollection.zip.data as Dictionary);
					break;
				}
			}
		}
	}
}